<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>取名</title>
<meta name="description" content="Hello world!">	
<meta name="keywords" content="web,page">
</head>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<body>
<h3>组合名字</h3>
<table>
	<tr>
	  <td>
	  	<textarea id="mz_words" style="width:300px; height:200px;">取 名 字</textarea>
	  </td>
	  <td>
	  	<input id="mz_ipt_submit" type="submit" class="btn btn-lg btn-primary"/>
	  </td>
	  <td>
	  	<textarea id="mz_result" style="width:300px; height:200px;"></textarea>
	  </td>
	</tr>
</table>

<h3>名字测分</h3>
<table>
	<tr>
	  <td>
	  	<textarea id="cf_words" style="width:300px; height:200px;"></textarea>
	  </td>
	  <td>
	  	<input id="cf_ipt_submit" type="submit" class="btn btn-lg btn-primary"/>
	  </td>
	  <td>
	  	<textarea id="cf_result" style="width:300px; height:200px;"></textarea>
	  </td>
	</tr>
</table>
使用前须知：<br>
新建一个chrome的快捷方式，在快捷方式的'属性'->'目标'的末尾上加上'<b> --disable-web-security</b>'。<br>
关闭所有的Chrome，通过快捷方式打开Chrome，即可使用。
<a href="http://camnpr.com/archives/chrome-args-disable-web-security.html" target="blank">详见</a>

<script type="text/javascript">
$(function(){
	$('#mz_ipt_submit').click(function(){
		var _wordsValue = $('#mz_words')[0].value;
		var _wordsArray = _wordsValue.split(' ');
		var _wordsNumber = 2;
		var _result = [];

		getWord(_wordsArray, _wordsNumber, _result);
		//console.log(_result);

		$('#mz_result')[0].value = _result.join('\n');
	});

	Array.prototype.clone=function(){ return this.slice(0); }
	function getWord(_wordsArray, _wordsNumber, _result, _words){
		_words = _words || [];
		for(var i = 0; i<_wordsArray.length; i++){
			var _w = _words.clone();
			_w.push(_wordsArray[i]);
			if( _words.length + 1 == _wordsNumber ){
				_result.push(_w.join(''));
			} else {
				_result.concat(_words, getWord(_wordsArray, _wordsNumber, _result, _w));
			}
		}
	}


	$('#cf_ipt_submit').click(function(){
		var _wordsValue = $('#cf_words')[0].value;
		var _wordsArray = _wordsValue.split('\n');
		$('#cf_result')[0].value = '';
		for(var i = 0; i<_wordsArray.length; i++){
			getScore(_wordsArray[i]);
		}
	});

	function getScore(wordName){
		var $result = $('#cf_result');
		$.ajax({
			type: "GET",
            url: "http://service.1518.com/iphone/gongsi.php",
            data:{
            	word: wordName,
            },
            cache: false,
            dataType: "text",
            success: function(xml) {
            	var score = $(xml).find('score').text();
		    	var originValue = $result[0].value;
		        $result[0].value = originValue + wordName + '\t' + score + '\n';
            }
		})
}
});
</script>
</body>
</html>